package com.shuoyue.ycgk.ui.mine.order;

import android.content.Intent;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.baseadapter.AppBaseQuickAdapter;
import com.shuoyue.ycgk.entity.Order;
import com.shuoyue.ycgk.entity.OrderGoods;
import com.shuoyue.ycgk.entity.SectionType;
import com.shuoyue.ycgk.ui.course.info.CourseInfoActivity;
import com.shuoyue.ycgk.ui.mine.vip.MyVipActivity;
import com.shuoyue.ycgk.ui.mine.wrong.SectionAdapter;
import com.shuoyue.ycgk.ui.papergroups.groupcommon.PaperCommonInfoActivity;
import com.shuoyue.ycgk.ui.papergroups.running.RunningInfoActivity;
import com.shuoyue.ycgk.ui.shop.ShopInfoActivity;
import com.shuoyue.ycgk.utils.SizeUtil;
import com.shuoyue.ycgk.utils.SpacesItemDecoration;

import java.util.ArrayList;
import java.util.List;

public class OrderAdapter extends AppBaseQuickAdapter<Order> {
    public OrderAdapter(@Nullable List<Order> data) {
        super(R.layout.item_order, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, Order item) {
        helper.addOnClickListener(R.id.lay_all);
        String statue = "";
        if (item.getProductType() == 2
                && item.getIsReceipt() == 1) {
            statue = "已发货";
        } else if (item.getProductType() == 2
                && item.getIsReceipt() == 0) {
            statue = "待发货";
        } else {
            statue = "已完成";
        }
        helper.setText(R.id.orderCode, item.getOrderNo());
        helper.setText(R.id.status, statue);
        helper.setText(R.id.payPrice, "合计：￥" + item.getPayPrice());


        RecyclerView recyclerView = helper.getView(R.id.goods);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        if (recyclerView.getTag() == null) {
            recyclerView.addItemDecoration(new SpacesItemDecoration(SizeUtil.dip2px(mContext, 8), false));
            recyclerView.setTag("tag");
        }
        List<OrderGoods> orderGoodsList = new ArrayList<>();
        OrderGoods orderG = new OrderGoods();
        orderG.setProductId(item.getProductId());
        orderG.setProductNum(item.getProductNum());
        orderG.setProductPrice(item.getProductPrice());
        orderG.setProductType(item.getProductType());
        orderG.setTitle(item.getTitle());
        orderGoodsList.add(orderG);

        OrderGoodsAdapter childAdapter = new OrderGoodsAdapter(orderGoodsList);
        recyclerView.setAdapter(childAdapter);
        childAdapter.setOnItemChildClickListener((adapter, view, position) -> {
            OrderGoods c = (OrderGoods) adapter.getItem(position);
            switch (c.getProductType()) {
                case 1://1：课程 2：图书 4：考前冲刺 5：会员  6 ,题包
                    mContext.startActivity(new Intent(mContext, CourseInfoActivity.class)
                            .putExtra("id", c.getProductId()));
                    break;
                case 2://1：课程 2：图书 4：考前冲刺 5：会员
                    mContext.startActivity(new Intent(mContext, ShopInfoActivity.class)
                            .putExtra("id", c.getProductId()));
                    break;
                case 4://1：课程 2：图书 4：考前冲刺 5：会员
                    mContext.startActivity(new Intent(mContext, RunningInfoActivity.class)
                            .putExtra("moduleId", c.getProductId()));
                    break;
                case 5://1：课程 2：图书 4：考前冲刺 5：会员
                    mContext.startActivity(new Intent(mContext, MyVipActivity.class));
                    break;
                case 6://1：课程 2：图书 4：考前冲刺 5：会员
                    PaperCommonInfoActivity.start(mContext, c.getProductId(), -1, -1);

                    break;
            }
        });

    }
}
